﻿using System;
using System.IO;

    class LogWriter
    {
        public enum LogWriteLevel
        {
            All,
            ErrorOnly,
            NoLog
        }
        public enum LogType
        {
            Info,
            Error
        }
        string _fileName;
        public string FileName
        {
            set { _fileName = value; }
        }
        LogWriteLevel _logLevel;
        public LogWriteLevel LogLevel
        {
            set { _logLevel = value; }

        }
        bool _timePrefix;
        public bool LogTimePrefix
        {
            set { _timePrefix = value; }
        }

        public void WriteToFile(string logToWrite)
        {
            try
            {

                FileInfo file = new FileInfo(_fileName);
                StreamWriter Tex = file.AppendText();
                Tex.WriteLine(logToWrite);
                Tex.Close();
            }
            catch (Exception exp)
            {
                //nothing to do ignore it
            }
        }

        public void WriteToFile(LogType type, string logToWrite)
        {
            try
            {
                if (_logLevel == LogWriteLevel.NoLog) return;
                if ((_logLevel == LogWriteLevel.ErrorOnly) && (type == LogType.Info)) return;

                if ((type == LogType.Error) && (_timePrefix))
                {
                    logToWrite = "Time:" + DateTime.Now.ToString() + ":Error!!!:" + logToWrite;
                }
                else if (type == LogType.Error)
                {
                    logToWrite = "Error!!!!" + logToWrite;
                }
                else if (_timePrefix)
                {
                    logToWrite = "Time:" + DateTime.Now.ToString() + ":" + logToWrite;
                }

                FileInfo file = new FileInfo(_fileName);
                StreamWriter Tex = file.AppendText();
                Tex.WriteLine(logToWrite);
                Tex.Close();
            }
            catch (Exception exp)
            {
                //Nothing to do
            }

        }
        public LogWriter()
        {
            _fileName = "LogWriter.log";
        }
    }
